package com.prs.crm.domain.sys;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;

import com.prs.crm.domain.hr.Person;

@Entity
@Table(name="sys_log")
public class Log   implements java.io.Serializable{

	private static final long serialVersionUID = 1L;
	
	@Id @GeneratedValue(strategy=GenerationType.IDENTITY)
	private Integer id;
	
	@ManyToOne
	private Module module;
	
	private Date accessTime;
	
	@ManyToOne
	private Person operator;
	
	private String ip;
	
	@OneToMany(mappedBy="log",fetch= FetchType.LAZY)
	@Cascade({org.hibernate.annotations.CascadeType.ALL,org.hibernate.annotations.CascadeType.DELETE_ORPHAN })
	private Set<LogItem> items;

	public void setId(Integer id) {
		this.id = id;
	}

	public Integer getId() {
		return id;
	}

	public void setModule(Module module) {
		this.module = module;
	}

	public Module getModule() {
		return module;
	}

	public void setAccessTime(Date accessTime) {
		this.accessTime = accessTime;
	}

	public Date getAccessTime() {
		return accessTime;
	}

	public void setOperator(Person operator) {
		this.operator = operator;
	}

	public Person getOperator() {
		return operator;
	}

	public void setItems(Set<LogItem> items) {
		this.items = items;
	}

	public Set<LogItem> getItems() {
		return items;
	}
	
	public void addItem(LogItem item)
	{
		if (items==null)
			items = new HashSet<LogItem>();
		items.add(item);
	}

	public void setIp(String ip) {
		this.ip = ip;
	}

	public String getIp() {
		return ip;
	}
}
